//
//  FourCollectionCell.swift
//  swiftTS
//
//  Created by 航电 on 2020/3/6.
//  Copyright © 2020 航电. All rights reserved.
//

import UIKit

class FourCollectionCell: UICollectionViewCell {
    
    fileprivate var imgView:UIImageView?;
    fileprivate var titleLb:UILabel?;
    
    var dataDic:Dictionary<String,AnyObject>?;
    
    override init(frame: CGRect) {
        super.init(frame: frame);
        
        self.onCreateUIForView();
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //TODO:UI
    fileprivate func onCreateUIForView() {
        self.imgView = UIImageView(frame: CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height*0.6));
        self.imgView?.contentMode = .scaleAspectFit;
        self.imgView?.backgroundColor = .clear;
        self.contentView.addSubview(self.imgView!);
        
        self.titleLb = UILabel(frame: CGRect(x: 0, y: (self.imgView?.frame.maxY)!, width: self.frame.width, height: self.frame.height-(self.imgView?.frame.maxY)!));
        self.titleLb?.textColor = .red;
        self.titleLb?.textAlignment = .center;
        self.titleLb?.font = UIFont.systemFont(ofSize: 14);
        self.contentView.addSubview(self.titleLb!);
        
        self.backgroundColor = .green;
    }
    
    //TODO:Actions
    func onChangeData(dic:Dictionary<String,AnyObject>) {
        self.dataDic = dic;
        self.setNeedsLayout();
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        if self.dataDic != nil {
            self.imgView?.image = UIImage(named: self.dataDic!["img"] as! String);
            self.titleLb?.text = (self.dataDic!["title"] as! String);
        }
    }
}
